package com.yesep.dao.plugin;

import com.alibaba.druid.pool.DruidDataSource;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.sql.SQLException;

/**
 * @program: envm
 * @description: 阿里巴巴数据源配置类
 * @author: quliang
 * @create: 2019-07-12 16:23
 **/
@Configuration
@EnableTransactionManagement
@MapperScan(value = "com.yesep.dao.mapper")
public class DruidConfig {

    private static final Logger log = LoggerFactory.getLogger(DruidConfig.class);


    @Bean(initMethod = "init", destroyMethod = "close")
    @ConfigurationProperties(prefix = "spring.datasource")
    public DruidDataSource dataSoure() throws SQLException {
        return new DruidDataSource();

    }

    @Bean
    public PlatformTransactionManager transactionManager() throws SQLException {
        return new DataSourceTransactionManager(dataSoure());
    }


}
